package edu.ynu.se.xiecheng.achitectureclass.util;

import edu.ynu.se.xiecheng.achitectureclass.service.DeviceService;
import edu.ynu.se.xiecheng.achitectureclass.service.GreenhouseService;
import edu.ynu.se.xiecheng.achitectureclass.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;

@Component
public class ScheduleTaskHandler {

    @Autowired
    private GreenhouseService greenhouseService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private StatisticService statisticService;

    @Scheduled(cron = "0 0/5 * * * ?")
    @Transactional
    public void performTask() {
        System.out.println("获取大棚数据中...");
        NetworkHandler.getStatistic(statisticService, deviceService);
        NetworkHandler.getCameraData(greenhouseService, statisticService, deviceService);
    }

}
